package com.etcn.common.json;

import java.io.Serializable;

import com.etcn.common.Enum.ReturnFlag;

/**
 * 通用返回结果封装类
 * @author guozc
 */
public class JResult implements Serializable {

	private static final long serialVersionUID = 1L;
	// 返回code(1:成功,0：失败)
	private Integer retCode = ReturnFlag.SUCCESS.value();
	// 返回信息
	private String retMsg = ReturnFlag.SUCCESS.reasonPhrase();
	// 返回数据
	private Object data;

	public JResult() {
	}
	
	public JResult(Integer retCode, String retMsg, Object data) {
		this.retCode = retCode;
		this.retMsg = retMsg;
		this.data = data;
	}

	public Integer getRetCode() {
		return retCode;
	}

	public void setRetCode(ReturnFlag flag) {
		this.retCode = flag.value();
	}

	public String getRetMsg() {
		return retMsg;
	}

	public void setRetMsg(String retMsg) {
		this.retMsg = retMsg;
	}

	public Object getData() {
		return data;
	}
	
	public <T> T getData(Class<T> valueType) {
		if(data == null){
			return null;
		}
		return (T)data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
	@Override
	public String toString() {
		return "retCode:"+retCode+" retMsg:"+retMsg+" data:"+data;
	}

}
